#ifndef __SCNS_LCD_H__
#define __SCNS_LCD_H__

#include "ScnsConfig.h"

#if defined(SCNS_LCD_ENABLE)&&SCNS_LCD_ENABLE==1

#include "ScnsYing.h"
#include "ScnsColor.h"
#include "ScnsBspLcd.h"
#include "ScnsLcd.table.h"
#include "ScnsLcd.color.h"

typedef enum
{
    SCNS_LCD_BACKGROUND_LIGHT_ON,
    SCNS_LCD_BACKGROUND_LIGHT_OFF,
}ScnsLcdBackgroundLightStatus;

typedef uint8 ScnsLcdLayer;

#define SCNS_LCD_LAYER_AUTO ((ScnsLcdLayer)-1)

extern ScnsStatus scnsLcdInit(void);
extern void scnsLcdSetBackgroundLight(ScnsLcdBackgroundLightStatus status);
extern void scnsLcdWorkModeSet(uint8 mode);
extern Point scnsLcdGetBorder(void);

extern Point scnsLcdGetPhysicalPlu(uint8 pD);
extern Point scnsLcdGetPhysicalPrd(uint8 pD);
extern Point scnsLcdGetPhysicalSize(uint8 pD);
extern Point scnsLcdGetPhysicalStart(uint8 pD);
extern ScnsLcdColor*scnsLcdGetPhysicalAddress(uint8 pD);

extern ScnsStatus scnsLcdLayerGet(ScnsLcdLayer*layN,uint8*needFree);
extern void scnsLcdLayerFree(ScnsLcdLayer*layN,uint8*needFree);
extern ScnsStatus scnsLcdLayerSetWindow(ScnsLcdLayer layN,Point plu,Point prd,Point*lastPlu,Point*lastPrd);
#define scnsLcdLayerAutoBegin()   uint8 __scnsLcdLayerAutoNeedFree;if(SCNS_STATUS_OK!=scnsLcdLayerGet(&layN,&__scnsLcdLayerAutoNeedFree)){goto __scnsLcdLayerAutoGOTO;}do{}while(0)
#define scnsLcdLayerAutoEnd()     scnsLcdLayerFree(&layN,&__scnsLcdLayerAutoNeedFree);__scnsLcdLayerAutoGOTO:;do{}while(0)

extern ScnsStatus scnsLcdSetAddress(ScnsLcdLayer layN,Point plu,Point prd,uint8 writeMode);
extern void scnsLcdWriteColor(ScnsLcdLayer layN,ScnsLcdColor color);
extern ScnsLcdColor scnsLcdReadColor(ScnsLcdLayer layN);
extern void scnsLcdWriteColors(ScnsLcdLayer layN,ScnsLcdColor color[],uint32 n);
extern void scnsLcdReadColors(ScnsLcdLayer layN,ScnsLcdColor color[],uint32 n);

extern void scnsLcdWritePixel(ScnsLcdLayer layN,Point plu,ScnsLcdColor color);
extern ScnsLcdColor scnsLcdReadPixel(ScnsLcdLayer layN,Point plu);

extern void scnsLcdFill(ScnsLcdLayer layN,Point plu,int16 w,int16 h,ScnsLcdColor color,uint8 merge);
extern void scnsLcdClear(ScnsLcdLayer layN,ScnsLcdColor color);
extern void scnsLcdMarkPhysical(ScnsLcdLayer layN);

extern void scnsLcdDisplayPoint(ScnsLcdLayer layN,Point plu,ScnsLcdColor color,uint8 merge);
extern void scnsLcdDisplayBigPoint(ScnsLcdLayer layN,Point plu,ScnsLcdColor color,uint8 merge);
extern void scnsLcdDisplayPolygon(ScnsLcdLayer layN,uint32 polySides,const Point poly[],ScnsLcdColor color,ScnsLcdColor bgColor,uint8 merge);

extern Point scnsLcdDisplayRawChar(ScnsLcdLayer layN,Point plu,const uint8*font,uint32 length,uint8 height,uint8 width,ScnsLcdColor color,ScnsLcdColor bgColor,uint8 merge);
extern Point scnsLcdDisplayChar(ScnsLcdLayer layN,Point plu,uint16 dat,const ScnsLcdFont*font,ScnsLcdColor color,ScnsLcdColor bgColor,uint8 merge);
extern Point scnsLcdDisplayString(ScnsLcdLayer layN,Point plu,const char dat[],const ScnsLcdFont*font,ScnsLcdColor color,ScnsLcdColor bgColor,uint8 merge);
extern Point scnsLcdDisplayStringRotate(ScnsLcdLayer layN,Point plu,const char dat[],uint32 i,uint32 l,uint32 n,const ScnsLcdFont*font,ScnsLcdColor color,ScnsLcdColor bgColor,uint8 merge);
extern Point scnsLcdDisplayInt8(ScnsLcdLayer layN,Point plu,int8 dat,const ScnsLcdFont*font,ScnsLcdColor color,ScnsLcdColor bgColor,uint8 merge);
extern Point scnsLcdDisplayUint8(ScnsLcdLayer layN,Point plu,uint8 dat,const ScnsLcdFont*font,ScnsLcdColor color,ScnsLcdColor bgColor,uint8 merge);
extern Point scnsLcdDisplayInt16(ScnsLcdLayer layN,Point plu,int16 dat,const ScnsLcdFont*font,ScnsLcdColor color,ScnsLcdColor bgColor,uint8 merge);
extern Point scnsLcdDisplayUint16(ScnsLcdLayer layN,Point plu,uint16 dat,const ScnsLcdFont*font,ScnsLcdColor color,ScnsLcdColor bgColor,uint8 merge);
extern Point scnsLcdDisplayInt32(ScnsLcdLayer layN,Point plu,int32 datt,uint8 num,const ScnsLcdFont*font,ScnsLcdColor color,ScnsLcdColor bgColor,uint8 merge);
extern Point scnsLcdDisplayUint32(ScnsLcdLayer layN,Point plu,uint32 dat,uint8 num,const ScnsLcdFont*font,ScnsLcdColor color,ScnsLcdColor bgColor,uint8 merge);
extern Point scnsLcdDisplayInt64(ScnsLcdLayer layN,Point plu,int64 dat,uint8 num,const ScnsLcdFont*font,ScnsLcdColor color,ScnsLcdColor bgColor,uint8 merge);
extern Point scnsLcdDisplayUint64(ScnsLcdLayer layN,Point plu,uint64 dat,uint8 num,const ScnsLcdFont*font,ScnsLcdColor color,ScnsLcdColor bgColor,uint8 merge);
extern Point scnsLcdDisplayFloat(ScnsLcdLayer layN,Point plu,float dat,int8 num,int8 pointNum,const ScnsLcdFont*font,ScnsLcdColor color,ScnsLcdColor bgColor,uint8 merge);
extern Point scnsLcdDisplayHexUint8(ScnsLcdLayer layN,Point plu,uint8 dat,const ScnsLcdFont*font,ScnsLcdColor color,ScnsLcdColor bgColor,uint8 merge);
extern Point scnsLcdDisplayHexUint16(ScnsLcdLayer layN,Point plu,uint16 dat,const ScnsLcdFont*font,ScnsLcdColor color,ScnsLcdColor bgColor,uint8 merge);
extern Point scnsLcdDisplayHexUint32(ScnsLcdLayer layN,Point plu,uint32 dat,const ScnsLcdFont*font,ScnsLcdColor color,ScnsLcdColor bgColor,uint8 merge);
extern Point scnsLcdDisplayHexUint64(ScnsLcdLayer layN,Point plu,uint64 dat,uint8 num,const ScnsLcdFont*font,ScnsLcdColor color,ScnsLcdColor bgColor,uint8 merge);

extern void scnsLcdDisplayXLine(ScnsLcdLayer layN,Point plu,Point prd,ScnsLcdColor color,uint8 merge);
extern void scnsLcdDisplayYLine(ScnsLcdLayer layN,Point plu,Point prd,ScnsLcdColor color,uint8 merge);
extern void scnsLcdDisplayLine(ScnsLcdLayer layN,Point plu,Point prd,ScnsLcdColor color,uint8 merge);
extern void scnsLcdDisplayLineK(ScnsLcdLayer layN,Point plu,Point prd,float k,ScnsLcdColor color,uint8 merge);

extern void scnsLcdDisplaySquare(ScnsLcdLayer layN,Point plu,Point prd,ScnsLcdColor bc,uint8 fill,ScnsLcdColor fc,uint8 merge);
extern void scnsLcdDisplayCircle(ScnsLcdLayer layN,Point plu,uint16 r,ScnsLcdColor bc,uint8 fill,ScnsLcdColor fc,uint8 merge);
extern void scnsLcdDisplayEllipse(ScnsLcdLayer layN,Point plu,uint16 a,uint16 b,ScnsLcdColor bc,uint8 fill,ScnsLcdColor fc,uint8 merge);
extern void scnsLcdDisplayRoundSquare(ScnsLcdLayer layN,Point plu,int16 bgw,int16 bgh,ScnsLcdColor bgc,int16 gaw,int16 gah,ScnsLcdColor fgc,int16 r,uint8 merge);

extern void scnsLcdDisplayArrayImage(ScnsLcdLayer layN,Point plu,const void*p,ScnsColorFormat format,const ScnsColorArgb8888*cult,int16 w,int16 h,int16 disW,int16 disH,uint8 merge);

extern const uint8*scnsLcdFontToRawChar(uint16 dat,const ScnsLcdFont*font,uint8*getHeight,uint8*getWidth,uint8*getRowByte);
extern const char*scnsLcdGetNextChar(const char*dat);
extern Point scnsLcdGetStringWidth(const char dat[],const ScnsLcdFont*font);

extern void scnsLcdDebugPrint(void);

#if defined(SCNS_IMAGE_ENABLE)&&SCNS_IMAGE_ENABLE==1

#include "ScnsImage.h"

extern const ScnsImage*scnsLcdDisplayImage(ScnsLcdLayer layN,Point plu,const ScnsImage*image,int16 disW,int16 disH,uint8 merge);
extern ScnsImage*scnsLcdScreenShot(ScnsColorFormat format,uint8 mergeBackground);
#if defined(SCNS_BMP_ENABLE)&&SCNS_BMP_ENABLE==1
extern void scnsLcdSave(FILE*fp,uint8 compress,uint8 close,uint8 mergeBackground);
#endif
#endif
extern void scnsLcdTest(ScnsLcdLayer layN);
extern Point scnsLcdTestFont(ScnsLcdLayer layN,Point plu,const ScnsLcdFont*font,ScnsLcdColor color,ScnsLcdColor bgColor,uint8 merge);
extern void scnsLcdBenchMark(ScnsLcdLayer layN,Point plu);
#endif
#endif

